﻿Chenxin.UI.UploadHousePicWin = Chenxin.extend(Chenxin.UI.FormCommon, {
    actionUrl: 'service/UploadHousePic.ashx',
    id: 'uploadHousePicdiv',
    renderTo: 'jqm_uploadHousePic',
    createForm: function() {
        return formCommon.UploadHousePicTable();
    },
    initEvent: function() {
		var _this=this;
        this.findByName('picType').live('click',function(){
			$('#div_uploadHouse').show();
			$('#div_uploadHouseBtn').show();
			$('#div_uploadHouse').empty();
			$('#div_uploadHouse').append('<input height="30" type="file" width="110" id="thumbnialUploadify" name="thumbnialUploadify" style="display: none;">');
			$("#thumbnialUploadify").uploadify({
				uploader: 'js/uploadify.swf',
				script: 'service/UploadHousePic.ashx?op=fileupload',
				cancelImg: 'images/cancel.png',
				scriptData:{houseid:_this.scope.currentHouseInfo.HouseId,CommunityId:_this.scope.currentHouseInfo.CommunityId,pictype:this.value,OprPersonId:_this.scope.currentHouseInfo.OprPersonId},
				buttonImg:'images/fileupload.png', 
				sizeLimit: 1048576,
				height: 24,
             width: 190,
				auto: false,
				multi: false,
				fileDesc: '支持格式:jpg', //如果配置了以下的'fileExt'属性，那么这个属性是必须的   
				fileExt: '*.jpg', //允许的格式
				onSelect: function(event, queueID, fileObj) {
				},
				onCheck:function(){
					 alert('xx');
				},
				onComplete: function(event, queueID, fileObj, response, data) {
					if(response){
						try{					
							eval("var json="+response);
							if(json.success==1){
								alert(json.msg);
								_this.scope.FillHousePic(_this.scope.currentHouseInfo.HouseId);
							}else if(json.success==0){
								alert(json.msg);
							}else{
								alert(json.msg);
								window.location.href=Chenxin.loginUrl;
							}
						}catch(e){
							alert('返回数据格式错误，文件上传失败！');
						}
					}
				},
				onError: function(event, queueID, fileObj) {
					alert("文件:" + fileObj.name + "上传失败");
				},
				onCancel: function(event, queueID, fileObj) {
					alert("取消了" + fileObj.name+"的上传");
				}
			});
		});
		$('#startupload').live('click', function() {
			$("#thumbnialUploadify").uploadifyUpload();
			//_this.hide();
		});
		$('#stopupload').live('click', function() {
			$("#thumbnialUploadify").uploadifyClearQueue();
		});
		$('#btnDel').live('click', function() {
		       if(!confirm("是否确认删除"))
		       {
		           return;
		       }
		       var picId="";
			    for(i=0;i<$('input[name="cbxPicId"]').length;i++)
			    {
			        if($('input[name="cbxPicId"]')[i].checked==true)
			        {
			             picId+="'"+$('input[name="cbxPicId"]')[i].value+"'"+",";
			        }
			    }
			   picId=picId.substring(0,picId.length-1);
	          Chenxin.ajax({
               type: "post",
               dataType: "json",
               url: "service/UploadHousePic.ashx?DelPic="+picId,
               onSuccess: function(data, msg) {
                alert(msg);
               }
             });		
              _this.scope.FillHousePic(_this.scope.currentHouseInfo.HouseId);
		   });
         $('#btnCancel').live('click', function() {
		        for(i=0;i<$('input[name="cbxPicId"]').length;i++)
		        {
		            $('input[name="cbxPicId"]')[i].checked=false;
		         }
	       });
    },
    initComponent: function() {
        Chenxin.UI.UploadHousePicWin.superclass.initComponent.call(this);
    }
});


Chenxin.UI.UploadHousePicTypeWin = Chenxin.extend(Chenxin.UI.FormCommon, {
    actionUrl: 'service/UploadHousePic.ashx',
    id: 'uploadHousePicTypediv',
    renderTo: 'jqm_uploadHousePicType',
    createForm: function() {
        return formCommon.UploadHousePicTypeTable();
    },
    initEvent: function() {
       

    },
    initComponent: function() {
        Chenxin.UI.UploadHousePicTypeWin.superclass.initComponent.call(this);
    }
});